require.config({
    baseUrl: '../js/lib', // 基础路径
    paths: {
        jquery: 'jquery',
        axios: 'axios'
    },
    shim: {

    }
});


require(['jquery'], function ($) {


    $(function () {
        const url = ['./template/sub-nav1.html', './template/sub-nav2.html', './template/sub-nav3.html', './template/sub-nav4.html', './template/sub-nav5.html', './template/sub-nav6.html', './template/sub-nav7.html', './template/sub-nav8.html'];
        $('.template>li').on('mouseover', function () {
            let index = $('.template>li').index(this);
            console.log(1);
            if (index == 8 || index == 9) return;

            $('.box').load(url[index], function () {
                console.log(1);
            });

            $('.box').animate({
                height: '250px'
            }, 200);
        });

        $('.template').on('mouseleave', function () {
            $('.box').animate({
                height: '0px'
            }, 200);
        })

        $('.delete').on('mouseover', function () {
            $('.box').animate({
                height: '0px'
            }, 200);
        })


    })

})

require(['jquery'], function ($) {
    $(function () {
        $('.nav-banner>ul>li').on('mouseenter', function () {
            let index = $('.nav-banner>ul>li').index(this);
            $('.sub-content').load('./template/banner-nav.html');
        })
        $('.nav-banner>ul').on('mouseleave', function () {
            $('.sub-content').empty();
        })
    })
})

require(['jquery'], function ($) {
    $(function () {


        $(window).on('scroll', function () {
            if ($(window).scrollTop() > 1000) {
                console.log(1);
                $('.fix_box>ul').css('bottom', '150px');
                $('.gotop').css('display', 'block');
            } else {
                $('.fix_box>ul').css('bottom', '50px');
                $('.gotop').css('display', 'none');
            }
        });

        $('.gotop').on('click', function () {
            $(window).scrollTop(0)
        })
    })
})

require(['jquery', 'axios'], function ($, axios) {
    axios.get('../product/getItems').then(res => {
        let data = res.data;
        let tempstring = '';
        console.log(data);
        data.forEach(el => {
            let picture = JSON.parse(el.picture);
            let pirce = JSON.parse(el.type)[0].pirce;
            tempstring +=
                `<li>
                    <a href="./show.html?product_id=${el.id}">
                        <img src="../${picture[0].src}" alt="">
                        <span>${el.title}</span>
                        <i>${el.deco}</i>
                        <b>${pirce}起</b>
                    </a>
                </li>`;
        });

        $('.m-r>ul').html(tempstring);

    }).catch(err => {
        console.log(err);
    });
});

require(['jquery', 'axios'], function ($, axios) {
    $(function () {
        let instance = axios.create({
            baseUrl: 'http://localhost:3000/'
        });

        instance.interceptors.request.use(function (config) {
            
            config.headers.authorization = localStorage.getItem('token');
            console.log(config);

            return config; 
        });

        
        instance.interceptors.response.use(function (response) {
            
            if (response.status === 404) return location.href = '404.html';
            return response.data;
        });



        instance.post('../users/getlogin').then(res => {
            console.log(1);
        }).catch(err => {
            console.log(err);
        });

    })
})